<?php include "checkSessionForAuthen.php"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Thay đổi thông tin món ăn</title>
		<?php include("import.php"); ?>
        <script type="text/javascript">
			$(document).ready(function() {
				$('#add').click(function() {
					return !$('#availableList option:selected').remove().appendTo('#relatedList');
				});
				
				$('#remove').click(function() {
					return !$('#relatedList option:selected').remove().appendTo('#availableList');
				});
			});
			
			function assignDish(){
                $('#form').attr('action', '../action/assignDishAction.php');
                $('#form').submit();
            }
        </script>
    </head>

    <body>
        <form action="menu.php" enctype="multipart/form-data" method="post" nam="form" id="form">
            <!--header-->
            <?php
            include "header.php";
            include_once("../service/dishService.php");
            include_once("../service/dayService.php");
            ?>
            <!--end header-->
            <!-- Container -->
            <div id="container">
                <div class="shell">

                    <!-- Message OK -->
                    <?php
                    $message = "";
                    if (isset($_GET['message'])) {
                        $deleteMessage = $_GET['message'];
                    }
                    if (isset($deleteMessage)) {
                        if ($deleteMessage == 'ok') {
                            $message = 'Thông tin thực đơn đã được thay đổi thành công!';
                        } else {
                            $message = 'Không thể thay đổi thông tin món ăn';
                        }
                    }

                    if ($message == '') {
                        $class = 'msg msg-ok msg-hidden';
                    } else {
                        $class = 'msg msg-ok';
                    }
                    ?>	
                    <div class="<?php echo($class); ?>" id="msgOK">
                        <p><strong><?php echo($message); ?></strong></p>
                        <a href="#" onclick="hideMessage()" class="close">close</a>
                    </div>
                    <!-- End Message OK -->

                    <br />
                    <!-- Main -->
                    <div id="main">
                        <div class="cl">&nbsp;</div>

                        <!-- Content -->
                        <div id="content">        
                            <!-- Box -->
                            <div class="box">
                                <!-- Box Head -->
                                <div class="box-head">
                                    <h2>Thực Đơn</h2>
                                </div>
                                <!-- End Box Head -->

                                <!-- Form -->
                                <?php
                                $days = getAllDays();
                                if (isset($_POST['day']))
                                    $dayId = $_POST['day'];
                                else if (isset($_GET['day']))
                                    $dayId = $_GET['day'];

                                if (!isset($dayId)) {
                                    $dayId = 1;
                                }
                                ?>
                                <div class="form">
                                    <p>
                                        <label>Thứ trong tuần</label>
                                        <select id="day" name="day" style="width:200px" class="field size1" onchange="document.getElementById('form').submit();">
                                            <?php
                                            while ($day = current($days)) {
                                                if (key($days) == $dayId) {
                                                    ?>
                                                    <option value="<?php echo(key($days)) ?>" selected="selected"><?php echo($day); ?></option>
                                                    <?php
                                                } else {
                                                    ?>
                                                    <option value="<?php echo(key($days)) ?>"><?php echo($day); ?></option>
                                                    <?php
                                                }
                                                next($days);
                                            }
                                            ?>
                                        </select>
                                    </p>
                                    <p>
                                        <!--<label>Món ăn cho ngày: </label>-->
                                        <table>
                                            <tr>
                                                <td>
                                                    <center>Món ăn hiện có</center>
                                                    <select name="availableList[]" id="availableList" size="10" multiple="multiple" class="categorylist">
                                                        <?php
                                                        $availableDishResult = getAvailableDish($dayId);
                                                        while ($availableRow = mysql_fetch_array($availableDishResult)) {
                                                            echo("<option value='" . $availableRow['DISH_ID'] . "'>" . $availableRow['DISH_NAME'] . "</option>");
                                                        }
                                                        ?>
                                                    </select>
                                                </td>
                                                <td><input type="button" value=">" class="button" id="add" /><br /><input type="button" value="<" class="button" id="remove" /></td>
                                                <td>
                                                    <center>Món ăn đã chọn:</center>
                                                    <select name="relatedList[]" id="relatedList" size="10" multiple="multiple" class="categorylist">
                                                        <?php
                                                        $selectedDishResult = getDishInDay($dayId);
                                                        while ($selectedRow = mysql_fetch_array($selectedDishResult)) {
                                                            echo("<option value='" . $selectedRow['DISH_ID'] . "'>" . $selectedRow['DISH_NAME'] . "</option>");
                                                        }
                                                        ?>
                                                    </select>
                                                </td>
                                            </tr>
                                        </table>
                                    </p>		
                                </div>
                                <!-- End Form -->

                            </div>
                            <!-- End Box -->

                        </div>
                        <!-- End Content -->	
                        <div class="cl">&nbsp;</div>			
                    </div>
                    <!-- Main -->
                </div>
            </div>
            <!-- End Container -->
            <!--footer-->
            <?php include "footer.php"; ?>
            <!--end footer-->
            <?php ConnectionManager::getInstance()->closeConnection(); ?>
        </form>
    </body>
</html>